import Mock from 'mockjs';
const count = 100;

let processedList = [];// 已处理
let b2cDetails = {
    productName: '洋柿子就是西红柿',
    productType: '电子产品',
    productNo: 12121,
    price: 4990,
    shelfState: '已上架',
    searchKey: '值得买、早下手',
    recommend: '这件商品是真的好',
    brand: '夕阳红',
    specsData: [
        {
            orderNo: '20181911',
            uuid: 'SKU00004',
            isDefault: true,
            buyName: '名称001',
            sellerName: '名称0033',
            startTime: '2019-12-06',
            state: '待签收',
            price: 4999.0,
            payMode: '支付宝'
        }
    ],
    specsAfterData: [
        {
            orderNo: '20181911',
            workNo: '20190809',
            uuid: 'SKU00004',
            userPhone: '13853628711',
            questionType: '售后咨询',
            userName: '张晓峰',
            creatName: '客服A',
            workOrderState: '待处理',
            isDefault: true,
            startTime: '2019-12-06',
            state: '待签收'
        }
    ]
};
let creatWorkOrder = {
    productName: '洋柿子就是西红柿',
    productType: '电子产品',
    productNo: 12121,
    price: 4990,
    shelfState: '已上架',
    searchKey: '值得买、早下手',
    recommend: '这件商品是真的好',
    brand: '夕阳红',
    specsData: [
        {
            orderNo: '20181911',
            uuid: 'SKU00004',
            isDefault: true,
            buyName: '名称001',
            sellerName: '名称0033',
            startTime: '2019-12-06',
            state: '待签收',
            price: 4999.0,
            payMode: '支付宝'
        }
    ],
    specsAfterData: [
        {
            orderNo: '20181911',
            workNo: '20190809',
            uuid: 'SKU00004',
            userPhone: '13853628711',
            questionType: '售后咨询',
            userName: '张晓峰',
            creatName: '客服A',
            workOrderState: '待处理',
            isDefault: true,
            startTime: '2019-12-06',
            state: '待签收'
        }
    ]
}
for (let i = 0; i < count; i++) {
    processedList.push(Mock.mock({
        'uuid': '@increment()', // 必须项
        'workNo': 'ORDER1000' + i,
        'orderNo': '2018101500' + i,
        'problemType': '售后咨询',
        'relationNo': '6598565' + i,
        'buyerName': '名称00' + i,
        'sellerName': '名称00' + i,
        'amountPayable': '￥100.00',
        'payMethod': '支付宝',
        'mobile|1': ['15508765363', '12308765363', '18708765363'],
        'usetName': '@cname',
        'createOper': '@cname',
        'state': '处理',
        'afterState': '售后成功',
        'createOpeTime': '@date(yyyy:MM:DD)',
        'actions|1': [
            [
                {
                    name: 'View',
                    label: '查看',
                    handleType: 'link'
                }
            ],
            [
                {
                    name: 'View',
                    label: '处理',
                    handleType: 'alert'
                }
            ]
        ]
    }))
}

export default [
    {
        path: '/api/getProcessedList',
        method: 'get',
        handle ({ body }) {
            const start = body.pageInfo.nowPage * body.pageInfo.pageShow - body.pageInfo.pageShow;
            const end = start + body.pageInfo.pageShow;
            let data = {
                return_code: 0,
                list: [...processedList].slice(start, end),
                pageInfo: {
                    nowPage: 1, // 当前页数
                    pageShow: body.pageInfo.pageShow, // 每页显示条数
                    totalPage: count / body.pageInfo.pageShow, // 总页数
                    totalNum: count // 总条数
                }
            }
            if (body.pageInfo.nowPage) {
                return {
                    code: 0,
                    msg: '获取数据成功',
                    data: data
                }
            } else {
                return {
                    code: 401,
                    msg: '接口请求超时',
                    data: {}
                }
            }
        }
    }, {
        path: '/api/getProcessedView',
        method: 'get',
        handle ({ body }) {
            if (body.uuid) {
                return {
                    code: 0,
                    msg: '',
                    data: {
                        data: b2cDetails,
                        return_code: 0
                    }
                }
            } else {
                return {
                    code: 401,
                    msg: '接口请求超时',
                    data: {}
                }
            }
        }
    }, {
        path: '/api/getCreatWorkView',
        method: 'get',
        handle ({ body }) {
            if (body.mobile) {
                return {
                    code: 0,
                    msg: '',
                    data: {
                        data: creatWorkOrder,
                        return_code: 0
                    }
                }
            } else {
                return {
                    code: 401,
                    msg: '接口请求超时',
                    data: {}
                }
            }
        }
    }, {
        path: '/api/getProcessed',
        method: 'get',
        handle ({ body }) {
            if (body.uuid) {
                let memberInfo = {};
                for (let i = 0; i < processedList.length; i++) {
                    if (Number(body.uuid) === processedList[i].uuid) {
                        memberInfo = processedList[i];
                        break;
                    }
                }
                return {
                    code: 0,
                    msg: '',
                    data: {
                        data: memberInfo,
                        return_code: 0
                    }
                }
            } else {
                return {
                    code: 401,
                    msg: '接口请求超时',
                    data: {}
                }
            }
        }
    },
    {
        path: '/api/addContract',
        method: 'get',
        handle ({ body }) {
            if (body.userName) {
                processedList.unshift(body.formData);
                return {
                    code: 0,
                    msg: '',
                    data: {
                        return_code: 0
                    }
                }
            } else {
                return {
                    code: 401,
                    msg: '接口请求超时',
                    data: {}
                }
            }
        }
    }

]
